﻿<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:odc="clr-namespace:Odyssey.Controls"
        xmlns:mwt="clr-namespace:Microsoft.Windows.Themes;assembly=PresentationFramework.Aero" xmlns:fx="clr-namespace:Odyssey.Effects"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
    <ResourceDictionary.MergedDictionaries>
        <ResourceDictionary Source="pack://application:,,,/Odyssey;Component/Themes/Ribbon/InternalRibbonButton.xaml" />
        <ResourceDictionary Source="pack://application:,,,/Odyssey;Component/Themes/Ribbon/DefaultRibbonButtonBrushes.xaml" />
        <ResourceDictionary Source="pack://application:,,,/Odyssey;Component/Themes/Ribbon/RibbonAppMenuItem.xaml" />
        <ResourceDictionary Source="pack://application:,,,/Odyssey;Component/Themes/Ribbon/RibbonApplicationButton.xaml" />
        <ResourceDictionary Source="pack://application:,,,/Odyssey;Component/Themes/Ribbon/RibbonGroupDropDownButton.xaml" />
    </ResourceDictionary.MergedDictionaries>

    <ControlTemplate TargetType="{x:Type odc:RibbonApplicationMenu}" x:Key="RibbonApplicationMenuControlTemplate">
        <Grid Margin="0">
            <odc:RibbonDropDownButton x:Name="PART_AppButton" IsFlat="False" Width="37" Height="37" PopupAnimation="Fade" Focusable="{TemplateBinding Focusable}" 
                    SnapsToDevicePixels="True" IsChecked="{Binding IsOpen, RelativeSource={RelativeSource TemplatedParent},Mode=OneWay}"
                    IsDropDownPressed="{Binding IsOpen, RelativeSource={RelativeSource TemplatedParent},Mode=TwoWay}"
                    Template="{DynamicResource {ComponentResourceKey odc:Skins, ApplicationMenuButtonTemplate}}" Foreground="White"
                    odc:RibbonBar.Size="Medium" CornerRadius="0,5,0,0"
                    Background="{DynamicResource {ComponentResourceKey odc:Skins, RibbonMenuButtonBrush}}">
                <odc:RibbonDropDownButton.Content>
                    <Image Width="24" Height="24" Source="{TemplateBinding MenuButtonImage}" x:Name="image"
                            Stretch="{Binding Path=(odc:RibbonButton.ImageStretch), RelativeSource={RelativeSource TemplatedParent}}"
                            RenderOptions.BitmapScalingMode="{Binding Path=(odc:ImageRenderOptions.SmallImageScalingMode), RelativeSource={RelativeSource TemplatedParent}}"
                            RenderOptions.EdgeMode="Unspecified" />
                </odc:RibbonDropDownButton.Content>
                <odc:RibbonDropDownButton.DropDownHeader>
                    <Grid Focusable="False">
                        <Border Background="{DynamicResource {ComponentResourceKey odc:Skins, RibbonBarControlBrush}}"
                                BorderBrush="{DynamicResource {ComponentResourceKey odc:Skins, BorderBrush}}" Focusable="False"
                                Padding="5,18,5,5" BorderThickness="1" CornerRadius="0,4,4,4">
                            <StackPanel Focusable="False">
                                <Border BorderBrush="White" BorderThickness="1" Focusable="False">
                                    <Border Background="{TemplateBinding Background}" BorderBrush="{TemplateBinding BorderBrush}"
                                            BorderThickness="{TemplateBinding BorderThickness}">
                                        <Grid Margin="-1,0,-1,0">
                                            <Grid.ColumnDefinitions>
                                                <ColumnDefinition Width="Auto" />
                                                <ColumnDefinition Width="*" />
                                            </Grid.ColumnDefinitions>

                                            <Border BorderThickness="0,0,1,0" BorderBrush="Gray" Grid.Row="0" Grid.Column="0">
                                                <ItemsPresenter />
                                            </Border>
                                            <StackPanel Grid.Column="1" Grid.Row="0" x:Name="PART_RecentItemsList">
                                                <ContentControl HorizontalAlignment="Stretch" Content="{TemplateBinding MenuHeader}"
                                                        ContentTemplate="{TemplateBinding MenuHeaderTemplate}" />
                                                <ContentControl Content="{TemplateBinding RecentItemsList}"
                                                        ContentTemplate="{TemplateBinding RecentItemsListTemplate}"
                                                        VerticalAlignment="Stretch" HorizontalAlignment="Stretch" />
                                                <ContentControl HorizontalAlignment="Stretch" Content="{TemplateBinding Footer}"
                                                        ContentTemplate="{TemplateBinding FooterTemplate}" />
                                            </StackPanel>

                                        </Grid>
                                    </Border>
                                </Border>
                                <ContentControl Content="{TemplateBinding Footer}" ContentTemplate="{TemplateBinding FooterTemplate}" />
                            </StackPanel>
                        </Border>

                        <!--This is an image of the actual menu button image which is simply duplicated.
                            The rectangle's Canvas.Left and Canvas.Top properties are modified by code so that is exactly over the button.-->
                        <Canvas>
                            <Rectangle Canvas.Left="0" Canvas.Top="0" IsHitTestVisible="False" Height="37" Width="37"
                                    x:Name="PART_AppButtonClone" VerticalAlignment="Top" HorizontalAlignment="Left"
                                    SnapsToDevicePixels="True">
                                <Rectangle.Fill>
                                    <VisualBrush Visual="{Binding ElementName=PART_AppButton}" Stretch="None"
                                            RenderOptions.BitmapScalingMode="HighQuality" />
                                </Rectangle.Fill>
                            </Rectangle>
                        </Canvas>

                    </Grid>
                </odc:RibbonDropDownButton.DropDownHeader>
            </odc:RibbonDropDownButton>
        </Grid>
        <ControlTemplate.Triggers>
            <MultiTrigger>
                <MultiTrigger.Conditions>
                    <Condition Property="IsEnabled" Value="False" />
                    <Condition Property="odc:RibbonChrome.IsGrayScaleEnabled" Value="True" />
                </MultiTrigger.Conditions>
                <Setter Property="RenderOptions.EdgeMode" Value="Unspecified" TargetName="image" />
                <Setter Property="RenderOptions.BitmapScalingMode" Value="Fant" TargetName="image" />
                <Setter Property="Effect" TargetName="image">
                    <Setter.Value>
                        <fx:GrayscaleEffect />
                    </Setter.Value>
                </Setter>
            </MultiTrigger>
            <Trigger Property="IsOpen" Value="False">
                <Setter Property="IsDropDownPressed" Value="False" TargetName="PART_AppButton" />
            </Trigger>
        </ControlTemplate.Triggers>
        <ControlTemplate.Resources>
            <Style TargetType="{x:Type odc:RibbonChrome}" BasedOn="{StaticResource RibbonChromeStyle}" />
        </ControlTemplate.Resources>

    </ControlTemplate>

    <Style TargetType="{x:Type odc:RibbonApplicationMenu}">
        <Setter Property="Width" Value="48" />
        <Setter Property="IsTabStop" Value="False" />
        <Setter Property="odc:KeyTip.XOffset" Value="20" />
        <Setter Property="odc:KeyTip.YOffset" Value="8" />
        <Setter Property="Background" Value="White" />
        <Setter Property="BorderBrush" Value="Gray" />
        <Setter Property="BorderThickness" Value="1" />
        <Setter Property="Template" Value="{StaticResource RibbonApplicationMenuControlTemplate}" />
        <Setter Property="MenuHeaderTemplate">
            <Setter.Value>
                <DataTemplate>
                    <Border BorderThickness="0,0,0,1" BorderBrush="Gray" Margin="1" Width="320"
                            Background="{DynamicResource {ComponentResourceKey odc:Skins, RibbonBarControlBrush}}" VerticalAlignment="Top"
                            HorizontalAlignment="Stretch">
                        <TextBlock Text="Recent Documents" FontWeight="Bold" TextAlignment="Center"
                                Foreground="{DynamicResource {ComponentResourceKey odc:Skins, RibbonBarForgroundBrush}}"
                                HorizontalAlignment="Center" VerticalAlignment="Center" />
                    </Border>
                </DataTemplate>
            </Setter.Value>
        </Setter>
    </Style>

</ResourceDictionary>